# FastAPI按定义顺序匹配路由，更具体的路由应放在前面
from fastapi import FastAPI
import uvicorn

app = FastAPI()

@app.get("/users/me")   # 更具体的路由放前面
async def read_user_me():
    return {"user_id": "the current user"}

@app.get("/users/{user_id}")    # 较通用的路由放后面
async def read_user(user_id: str):
    return {"user_id": user_id}

if __name__ == "__main__":
    uvicorn.run(app, host="127.0.0.1", port=8000)

# 访问：http://127.0.0.1:8000/users/me  # 匹配到/users/me路由
# 访问：http://127.0.0.1:8000/users/123456  # 匹配到/users/{user_id}路由
